package com.xq.tmall.util;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

import java.net.UnknownHostException;
import java.util.List;

/**
 * Author : JiangLinHan
 * Date : 2019/9/9
 * Time : 10:22
 **/

@Configuration
public class MyRedisConfig {
    @Bean(name="genericJackson2JsonRedisSerializer")
    public GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }

    @Bean(name = "myRedisTemplate")
    public RedisTemplate<Object, List<Object>> myRedisTemplate(RedisConnectionFactory redisConnectionFactory,
                                                              GenericJackson2JsonRedisSerializer ser) throws UnknownHostException {
        RedisTemplate<Object, List<Object>> template = new RedisTemplate();
        template.setConnectionFactory(redisConnectionFactory);
        //设置序列化方法
        template.setDefaultSerializer(ser);
        return template;
    }

}
